package com.honeycomb.user.dto;

import java.util.Arrays;

import com.honeycomb.utils.MyDateDTTM;

/**
 * 用户Dto
 * 
 * @author Wangyu
 */
public class UserinfoDto implements Cloneable {
	
	private Long userId;
	private String userNickname;
	private Sex userSex;
	private MyDateDTTM userBirthday;
	private String userHeadImagUrl;
	private MyDateDTTM userRegistDttm;
	private String userRegistIp;
	private String statement;


	public UserinfoDto(Long id) {
		this.userId = id;
	}
	
	public Long getUserId() {
		return userId;
	}
	public String getUserNickname() {
		return userNickname;
	}
	public void setUserNickname(String userNickname) {
		this.userNickname = userNickname;
	}
	public Sex getUserSex() {
		return userSex;
	}
	public void setUserSex(Sex userSex) {
		this.userSex = userSex;
	}
	public MyDateDTTM getUserBirthday() {
		return userBirthday;
	}
	public void setUserBirthday(MyDateDTTM userBirthday) {
		this.userBirthday = userBirthday;
	}
	public MyDateDTTM getUserRegistDttm() {
		return userRegistDttm;
	}
	public void setUserRegistDttm(MyDateDTTM userRegistDttm) {
		this.userRegistDttm = userRegistDttm;
	}
	public String getUserRegistIp() {
		return userRegistIp;
	}
	public void setUserRegistIp(String userRegistIp) {
		this.userRegistIp = userRegistIp;
	}
	public String getUserHeadImagUrl() {
		return userHeadImagUrl;
	}
	public void setUserHeadImagUrl(String userHeadImagUrl) {
		this.userHeadImagUrl = userHeadImagUrl;
	}
	
	public String getStatement() {
		return statement;
	}
	public void setStatement(String statement) {
		this.statement = statement;
	}
	
	public String showBirthdayInString() {
		return userBirthday.formatDTString();
	}
	
	public String showRegisterDateInString() {
		return userRegistDttm.formatToDTTMString();
	}
	
	@Override
	public UserinfoDto clone() {
		UserinfoDto newInfo = new UserinfoDto(userId);
		newInfo.setUserNickname(userNickname);
		newInfo.setUserSex(userSex);
		newInfo.setUserBirthday(userBirthday);
		newInfo.setUserHeadImagUrl(userHeadImagUrl);
		newInfo.setUserRegistDttm(userRegistDttm);
		newInfo.setUserRegistIp(userRegistIp);
		newInfo.setStatement(statement);
		
		return newInfo;
	}
	
	public enum Sex {
		MALE(0),
		FEMALE(1);
		
		private int intValue;
		
		private Sex(int intValue) {
			this.intValue = intValue;
		}
		
		/**
		 * 根据传入字符串来返回对应的状态类型
		 */
		public static Sex getSex(String strValue) {
			try {
				Sex type = valueOf(strValue);
				return type;
			}
			catch(Exception ex) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in Sex. Only "
						+ Arrays.toString(Sex.values()) + " are allowed."
						);
			}
		}
		
		/**
		 * 根据传入INT值来返回对应的状态类型
		 */
		public static Sex getSex(int intValue) {
			for (Sex elem : Sex.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}

			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in Sex.");
		}

		/**
		 * 返回int值类型。
		 * @return
		 */
		public int toIntValue() {
			return intValue;
		}
	};
	
}
